package xin.printk.android.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import xin.printk.android.R;
import xin.printk.android.data.entity.HomeItem;

public class HomeRecyclerAdapter extends AbstractRecyclerAdapter<HomeItem> {

    public HomeRecyclerAdapter(Context context, List<HomeItem> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder createContentHolder(ViewGroup parent) {
        return new ListHolder(LayoutInflater.from(mContext)
                .inflate(R.layout.item_home, parent, false));
    }

    @Override
    public void bindContentHolder(RecyclerView.ViewHolder holder, int position) {
        ListHolder listHolder = (ListHolder) holder;
        listHolder.image.setImageResource(mData.get(position).getImage());
        listHolder.title.setText(mData.get(position).getTitle());
        listHolder.description.setText(mData.get(position).getDescription());
        listHolder.tips.setTextColor(mData.get(position).getColor());
    }

    static class ListHolder extends RecyclerView.ViewHolder {

        ImageView image;
        TextView title;
        TextView description;
        TextView tips;

        ListHolder(View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.img_home);
            title = itemView.findViewById(R.id.tv_home_data_title);
            description = itemView.findViewById(R.id.tv_home_data_description);
            tips = itemView.findViewById(R.id.tv_home_more_tips);
        }
    }
}
